﻿using System.Windows.Forms;

namespace EFMLEditor.Internal.Controls
{
    public partial class ErrorLister : UserControl
    {
        public ErrorLister()
        {
            InitializeComponent();
        }

        public void Reload()
        {
            this.ReloadSections();
            this.ReloadErrors();
        }

        public int ErrorsCount
        {
            get
            {
                return listBox1.Items.Count;
            }
        }

        private void ReloadSections()
        {
            comboBox1.Items.Clear();

            comboBox1.Items.Add("All");

            foreach (var s in ErrorContainer.GetSections())
            {
                comboBox1.Items.Add(s);
            }
            comboBox1.SelectedIndex = 0;
        }
        private void ReloadErrors()
        {
            listBox1.Items.Clear();
            if(comboBox1.SelectedIndex == 0)
            {
                foreach (var error in ErrorContainer.GetErrors())
                {
                    listBox1.Items.Add(error.Section + ": " + error.Message);
                }
            }
            else
            {
                foreach (var error in ErrorContainer.GetErrors())
                {
                    if(error.Section == comboBox1.SelectedItem.ToString())
                        listBox1.Items.Add(error.Message);
                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            this.ReloadErrors();
        }
    }
}
